package com.hziee.graduate.ticket.dao;

import java.time.LocalDateTime;
import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hziee.graduate.ticket.vo.AreaVO;
import org.apache.ibatis.annotations.Param;
import com.hziee.graduate.ticket.entity.Schedule;
import org.apache.ibatis.annotations.Select;


public interface ScheduleDao extends BaseMapper<Schedule> {

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<Schedule> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<Schedule> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<Schedule> 实例对象列表
     * @return 影响行数
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<Schedule> entities);

    @Select("SELECT *\n" +
            "FROM t_schedule\n" +
            "WHERE date <= #{relieveTime} and room_id = #{roomId}\n" +
            "ORDER BY date desc\n" +
            "limit 0,1")
    Schedule getLatestScheduleBeforeDate(@Param("relieveTime") String relieveTime, @Param("roomId") Long roomId);

    @Select("select count(*) from t_schedule\n" +
            "where room_id = #{roomId} and date=#{item2}")
    Integer getScheduleCountByDate(@Param("roomId")Long roomId, @Param("item2")String item2);
}

